package com.demo.producer;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

//发信息
public class Producer_HelloWork {
    public static void main(String[] args) throws Exception {

        //1.创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //2.设置一些参数
        factory.setHost("127.0.0.1");
        factory.setPort(5672);
        factory.setUsername("guest");
        factory.setPassword("guest");
        //3.创建连接 Connection
        Connection connection = factory.newConnection();
        //4.创建Channel
        Channel channel = connection.createChannel();
        //5.创建队列Queue
        /*
        String queue, boolean durable,
        boolean exclusive, boolean autoDelete,
        Map<String, Object> arguments
        1.queue 队列名称
        2.durable 是否持久化 当mq重启之后，还在
        3.exclusive：
          是否独占，只能有一个消费者监听这一列
          当connection时，是否删除队列
        4.autoDelete：是否自动删除。当没有Consumer时自动删除掉
        5.arguments：参数
         */
        channel.queueDeclare("hello word456", true, false, true, null);
        String body = "hello rabbitmq...";
        //6.发送消息
        channel.basicPublish("","hello word456", null, body.getBytes());

        //释放资源
//        channel.close();
//        connection.close();
    }
}